//手机号验证
var Val = {
    isMobile: function (s) {
        var regu = /(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/;
        var re = new RegExp(regu);
        return re.test(s);
    },
    IsPassWord: function (p) {
        var regp = /^[a-zA-Z]\w{5,17}$/;
        var re = new RegExp(regp);
        return re.test(p);
    }
}
$(function () {
    $('.LogInImg input').eq(0).focus(function () {
        $('.LogInImg img').eq(0).attr('src', '/images/LogNameFocus.png');
    }).blur(function () {
        $('.LogInImg img').eq(0).attr('src', '/images/LogName.png');
    });
    $('.LogInImg input').eq(1).focus(function () {
        $('.LogInImg img').eq(1).attr('src', '/images/LogWordFocus.png');
    }).blur(function () {
        $('.LogInImg img').eq(1).attr('src', '/images/LogWord.png');
    });

    $('.LogInDel').on('click', function () {
        $('.LogInImg input').eq(1).val('');
        $('.LogInImg input').eq(1).focus();
    });
    $('.KeJian').on('click', function () {
        if ($('.LogInWord input').attr('type') == 'text') {
            $('.LogInWord input').attr('type', 'password');
            $('#PassWordVisibale').attr('style', 'display:none;');
            $('#PassWordInVisibale').attr('style', 'display:block;');
        }
        else {
            $('.LogInWord input').attr('type', 'text');
            $('#PassWordInVisibale').attr('style', 'display:none;');
            $('#PassWordVisibale').attr('style', 'display:block;');
        }
    });

    $('.LogInCheckbox').click(function () {
        if ($(this).attr('value') == "1") {
            $(this).css('background', 'url(/images/CheckboxNone.png) no-repeat 0 center/16px 16px ');
            $(this).css('backgroundSize', '16px 16px');
            $(this).attr('value', '2');
        }
        else {
            $(this).css('background', 'url(/images/Checkbox.png) no-repeat 0 center/16px 16px');
            $(this).css('backgroundSize', '16px 16px');
            $(this).attr('value', '1');
        }
    });
    //注册页面的获取验证码
    var InputTime = null,
		InputNum = 0;
    $('.LogInYZM input:eq(1)').click(function () {
        $('.LogInYZM input:eq(1)').css('color', '#666')
        InputTime = setTimeout(function () {
            InputNum = InputNum + 1;
            /*if(InputNum == 2){
				$('.LogInYZM input:eq(1)').css('color','#ff571f')
				clearTimeout(InputTime);
			}*/
        }, 1000);

    })

    //Order下单Page
    $('.OrderPay').each(function (index) {
        $('.OrderPay').eq(index).on('click', function () {
            $('.OrderPay img').attr('src', '/images/OrderPayF.png');
            $('.OrderPay img').attr('select', '0');
            $('.OrderPay img').eq(index).attr('src', '/images/OrderPayT.png');
            $('.OrderPay img').eq(index).attr('select', '1');
        });
    });
    var $OrderNum;
    $('.OrderPartThree .OrderAdd').click(function () {
        $OrderNum = parseInt($(this).parent().children('span').text());
        $OrderNum = $OrderNum + 1;
        $(this).parent().children('span').text($OrderNum);
    })
    $('.OrderPartThree .OrderPlus').click(function () {
        $OrderNum = parseInt($(this).parent().children('span').text());
        $OrderNum = $OrderNum - 1;
        if ($OrderNum == 0) {
            $(this).parent().parent().parent().remove();
        }
        $(this).parent().children('span').text($OrderNum);
    });


    //addAddress
    $('.mod_input .check a').each(function (index) {
        $('.mod_input .check a').eq(index).click(function () {
            $('.Input_check').removeClass('input_checked');
            $('.Input_check').addClass('input_uncheck');

            $(this).children('.Input_check').removeClass('input_uncheck');
            $(this).children('.Input_check').addClass('input_checked');
        })
    })
    //addressManage
    $('.addressList li').each(function (index) {
        $('.addressList li').eq(index).click(function () {
            $('.addressList li .item').removeClass('active');
            $('.addressList li .item').eq(index).addClass('active');
        })
    })
    $('.lay_right .btn_send').click(function () {
        if ($('.lay_right .btn_send').attr('value') == '1') {
            $('.lay_right .btn_send').attr('value', '0');
            $('.lay_right .btn_send img').attr('src', '/images/DeliveryAddrEdit.png');
            $('.btn-edit').hide();
            $('.btn-delete').show();
        } else {
            $('.lay_right .btn_send').attr('value', '1');
            $('.lay_right .btn_send img').attr('src', '/images/DeliveryAddrDelBtn.png');
            $('.btn-edit').show();
            $('.btn-delete').hide();
        }
    });
    $('.btn-delete').click(function () {
        $(this).parent().parent().remove();
    })

    //MineOrder
    $('.MineCon nav li').each(function () {
        $('.MineCon nav li').click(function () {
            $('.MineCon nav li').removeClass('MineNavFocus');
            $(this).addClass('MineNavFocus');
        })
    })

    //登录页头像点击图片变化效果
    $('.HeadImg').mousedown(function () {
        $(this).attr('src', '../images/icon_down.png');
    })
    $('.HeadImg').mouseup(function () {
        $(this).attr('src', '../images/icon_normal.png');
    })
    $('.UserInfoHeadImg').mousedown(function () {
        $(this).attr('src', '../images/icon_down.png');
    })
    $('.UserInfoHeadImg').mouseup(function () {
        $(this).attr('src', '../images/icon_normal.png');
    })
});

///组合服务器接口URL方法
function appendServerUrl(command) {
    var host = "http://weixin.superstore5000.com:5005/";
    var type = "from=weixin&type=";
    var typevar = 1;
    var url = host.toString() + command.toString() + "?" + type.toString() + typevar.toString();
    return url;
}

/// <summary>
/// 显示规则：
/// 1.如果送货时间在当前时间的一个小时之内，显示“一小时内送达”
/// 2.如果送货时间是当前时间的明天或者后天，显示“明天/后天+具体时间”
/// 3.如果送货时间不是上面的情况，显示具体的时间“年月日小时”
/// </summary>
/// <param name="start"></param>
/// <param name="end"></param>
function getDeliveryTime(start, end) {
    var year = start.getFullYear();
    var month = start.getMonth() + 1;
    var day = start.getDate();
    var hourStart = start.getHours();
    var hourEnd = end.getHours();
    var currentDate = new Date();
    var currentYear = currentDate.getFullYear();
    var currentMonth = currentDate.getMonth() + 1;
    var currentDay = currentDate.getDate();
    var currentHour = currentDate.getHours();
    if (year == currentYear && month == currentMonth && day == currentDay && hourStart == currentHour) {
        return "一小时内送达";
    } else if (year == currentYear && month == currentMonth && day == (currentDay + 1)) {
        var str = "明天 " + hourStart + ":00-" + hourEnd + ":00";
        return str.toString();
    } else if (year == currentYear && month == currentMonth && day == (currentDay + 2)) {
        var str = "后天 " + hourStart + ":00-" + hourEnd + ":00";
        return str.toString();
    } else {
        var str = year + "-" + month + "-" + day + " " + hourStart + ":00-" + hourEnd + ":00";
        return str.toString();
    }
};
///根据选择的时间得出送货的起止时间
function setDeliveryTime(delTime) {
    var delTimeStr = delTime.toString();
    var currentDate = new Date();
    var currentYear = currentDate.getFullYear();
    var currentMonth = currentDate.getMonth() + 1;
    var currentDay = currentDate.getDate();
    var currentHour = currentDate.getHours();
    var day,startHourNum, endHourNum;
    if (delTimeStr == "一小时内送达") {
        day = "今天";
        startHourNum = currentHour;
        endHourNum = currentHour + 1;
    }
    else {
        var strs = new Array();
        strs = delTimeStr.split(' ');
        day = (strs[0]).toString();
        var hourStr = (strs[1]).toString();
        var hours = new Array();
        hours = hourStr.split('-');
        var startHour = hours[0].toString();
        var endHour = hours[1].toString();
        startHourNum = Number(startHour.substring(0, 1));
        endHourNum = Number(endHour.substring(0, 1));
    }

    var startTimeNum, endTimeNum;
    if (day == "今天") {
        startTimeNum = Number(Date.UTC(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), startHourNum));
        endTimeNum = Number(Date.UTC(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), endHourNum));
    } else if (day == "明天") {
        startTimeNum = Number(Date.UTC(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()+1, startHourNum));
        endTimeNum = Number(Date.UTC(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()+1, endHourNum));
    } else if (day == "后天") {
        startTimeNum = Number(Date.UTC(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()+2, startHourNum));
        endTimeNum = Number(Date.UTC(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()+2, endHourNum));
    }
    var timeStr = startTimeNum.toString() + "-" + endTimeNum.toString();
    return timeStr;
}
